home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
src
/
fig14_08.jar
/
Ch14
/
Fig14_08
/
Fig14_08.paul
< prev
next >
Wrap
Text File
|
1997-08-26
|
2KB
|
92 lines
// fig14_8.cpp
// Credit inquiry program
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
void outputLine( int, char*, double );
main()
{
ifstream inClientFile( "clients.dat", ios::in );
if ( !inClientFile ) {
cerr << "File could not be opened" << endl;
exit( 1 );
}
cout << "Enter request\n"
<< " 1 - List accounts with zero balances\n"
<< " 2 - List accounts with credit balances\n"
<< " 3 - List accounts with debit balances\n"
<< " 4 - End of run\n? ";
int request;
cin >> request;
while ( request != 4 ) {
int account;
char name[ 10 ];
double balance;
inClientFile >> account >> name >> balance;
switch (request) {
case 1:
cout << endl << "Accounts with zero balances:" << endl;
while (!inClientFile.eof()) {
if (balance == 0)
outputLine(account, name, balance);
inClientFile >> account >> name >> balance;
}
break;
case 2:
cout << endl << "Accounts with credit balances:"
<< endl;
while (!inClientFile.eof()) {
if (balance < 0)
outputLine(account, name, balance);
inClientFile >> account >> name >> balance;
}
break;
case 3:
cout << endl << "Accounts with debit balances:"
<< endl;
while (!inClientFile.eof()) {
if (balance > 0)
outputLine(account, name, balance);
inClientFile >> account >> name >> balance;
}
break;
}
inClientFile.clear(); // reset eof for next input
inClientFile.seekg(0); // position to beginning of file
cout << endl << "? ";
cin >> request;
}
cout << "End of run." << endl;
return 0;
}
void outputLine(int acct, char *name, double bal)
{
cout << setiosflags(ios::left) << setw(10) << acct
<< setw(13) << name << setw(7) << setprecision(2)
<< setiosflags(ios::showpoint | ios::right)
<< bal << endl;
}